<?
class obres {
	var $xml;
	var $types_xml;
	function loadXml(){
		$d = file_get_contents(ROOT.'database.xml');
		$this->xml = new SimpleXMLElement($d);
		return $this->xml;
	}
	function loadXmlTypes(){
		$d = file_get_contents(ROOT.'database_types.xml');
		$this->types_xml = new SimpleXMLElement($d);
		return $this->types_xml;
	}
	function toARdata(){
		$r = array();
		$c = 0;
		$c2= 0;
		foreach($this->xml->DatosWS as $point){
			$tn = (string)$point->C;
			if(empty($r[$tn])){
				$r[$tn] = array('id'=>$c2,'nodes'=>array(),'nom'=>'aaaa');
			}
			$image = (string)$point->image;
			if(strpos($image,'http')===false) $image = IMAGE_SERVER.$image;
			$r[$tn]['nodes'][] = array(
				'id'=> (int) $point->Id
				,'lat' => (float) ($point->lat?$point->lat:41.40326856823383)/*$point->lat*/
				,'lng' => (float) ($point->lng?$point->lng:(2.193665164708700+$c))/*$point->lng*/
				,'nom' => (string) $point->N
				,'url' => (string) $point->U
				,'photo_url' => (string) $image
			);
			$c += 0.00001;
			++$c2;
		}
		
		foreach($this->types_xml->type as $tp){
			foreach($r as $i => $v){
				if($i==(string)$tp->id){
					$r[$i]['nom'] = (string)$tp->name;
					$image = (string)$tp->image;
					if(strpos($image,'http')===false) $image = IMAGE_SERVER.$image;
					$r[$i]['icono'] = $image;
				}
			}
		}
		return $r;
	}
}
?>